/*
 *   Copyright (C) 2007 by Andrzej Oczkowicz
 *   andrew_lz@poczta.fm
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 *   KMediaCatalog :)
 *
 */

#include <QDir>
#include <QApplication>
#include "kconfig.h"
#include "dbg.h"
#include "kinfo.h"

kConfig::kConfig(QObject *parent)
 : QObject(parent)
{
}


kConfig::~kConfig()
{
}

QString kConfig::configDir()
{
  QString home ( QDir::home().path() );
  home += QDir::separator();
  home += ".";
  home += APP_NAME;
  home += QDir::separator();
  QDir().mkpath ( home );
  return home;
}

QString kConfig::modulesDir(pathLocation p)
{
  return dataDir(p) + "modules" + QDir::separator();
}

QString kConfig::dataDir(pathLocation p)
{
  switch (p){
    case pathUser: {
      return configDir();
      break;
    }
    case pathSystem: {
        QString d( exeName().section(QDir::separator(), 1, -3) + QDir::separator() ) ;
    #ifdef Q_OS_WIN32
        return d;
     #endif
        return QDir::separator() + d;
      break;
    }
  }
  return "";
}

QString kConfig::exeName()
{
  #ifdef Q_OS_WIN32
    return QApplication::arguments().at(0);
  #else
    QFileInfo f("/proc/self/exe");
    QString exe( f.symLinkTarget() );
    return exe;
  #endif
}


